from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import HttpResponse


class CorsMiddleware(MiddlewareMixin):
    def process_request(self, request):
        print('roding.....')
        if request.method == "OPTIONS":
            return HttpResponse()

    def process_response(self, request, response):
        # 允许所有人向我发请求
        print('outing.......')
        response['Access-Control-Allow-Origin'] = '*'
        response['Access-Control-Allow-Headers'] = '*'
        response['Access-Control-Allow-Method'] = '*'

        return response
